package com.mybatis.core.repository.mapper;

import com.mybatis.core.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author xieshue
 * @date 2017\11\14 0014
 */
public interface UserMapper {
    /**
     * 根据用户ID获取用户
     *
     * @param id
     * @return
     */
    @Select("select * from t_user where id = #{id}")
    User findOne(@Param(value = "id") Long id);

    @Select("select * from t_user")
    List<User> findAll();

    @Insert("<script>insert into t_user(login_name,user_name,password,email,phone) values " +
            "<foreach collection =\"list\" item=\"user\" index= \"index\" separator =\",\">" +
            "(#{user.loginName},#{user.userName},#{user.password},#{user.email},#{user.phone})" +
            "</foreach ></script>")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertBatch(List<User> users);

    @Insert("insert into t_user(id,login_name,user_name,password,email,phone) values(#{id},#{loginName},#{userName},#{password},#{email},#{phone})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(User user);
}
